package com.xuecheng.search.interfaces.web;

import com.xuecheng.search.application.service.IndexApplication;
import com.xuecheng.search.domain.model.po.CourseIndex;
import com.xuecheng.search.infrastructure.constant.EsIndexConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-08-31  21:51
 */
@Api(tags = "索引接口")
@RestController
@RequestMapping("/index")
public class IndexApi {

    @Autowired
    private IndexApplication indexApplication;

    @Value("${elasticsearch.course.index}")
    public String courseIndexName;

    @ApiOperation("添加课程索引")
    @PostMapping("/course")
    public Boolean addIndex(@RequestBody CourseIndex courseIndex){

        return indexApplication.addIndex(courseIndexName, courseIndex.getId().toString(), courseIndex);
    }
}
